// 默认异步迭代器
class Emitter {
  constructor(max) {
    this.max = max;
    this.asyncIdx = 0;
  }

  async *[Symbol.asyncIterator]() {
    while (this.asyncIdx < this.max) {
      yield await new Promise((resolve) => (setTimeout(() => resolve(this.asyncIdx++), 1000)))
    }
    console.log('执行完了')
  }
}

async function asyncCount() {
  const emitter = new Emitter(5);
  // const ge = emitter[Symbol.asyncIterator]()
  // ge.next().value
  // ge.next().value
  // ge.next().value
  // ge.next().value
  // ge.next().value
  // ge.next().value
  for await (let x of emitter) {
    console.log(`当前值为： ${x}`)
  }
}

asyncCount();
